package com.gkt.ec.cms.activity.service.impl;

import com.github.pagehelper.PageInfo;
import com.gkt.ec.cms.activity.dao.CustomerVehicleDao;
import com.gkt.ec.cms.activity.model.domain.CustomerActivityEntity;
import com.gkt.ec.cms.activity.model.domain.CustomerVehicle;
import com.gkt.ec.cms.activity.model.domain.CustomerVehicleEntity;
import com.gkt.ec.cms.activity.model.pojo.SearchCustomerVO;
import com.gkt.ec.cms.activity.service.CustomerVehicleService;
import com.gkt.ec.commons.persistence.entity.search.CouponSearch;
import com.gkt.ec.commons.shared.commons.service.CrudService;
import com.gkt.ec.commons.shared.persistence.PageQuery;

import org.apache.ibatis.session.RowBounds;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * Created by 14081593 on 2015/11/28.
 */
@Service("CustomerVehicleService")
public class CustomerVehicleServiceImpl extends CrudService<CustomerVehicleDao, CustomerVehicleEntity> implements CustomerVehicleService {

    private static final PageQuery<CustomerVehicle> page = null;

    public PageInfo<CustomerVehicle> queryByPage(SearchCustomerVO vo, int offset, int max) {

        vo.setSkip(offset);
        vo.setEnd(max);

        int total = dao.countByPage(vo);
        List<CustomerVehicle> clist = dao.selectByPage(vo);
        PageInfo<CustomerVehicle> info = new PageInfo<CustomerVehicle>(clist);
        info.setTotal(total);
        return info;
    }

    public List queryVehicleBrand() {
        return dao.queryVehicleBrand();
    }

    public List queryBindCustomers(Long activityId) {
        return dao.queryBindCustomers(activityId);
    }


    public PageInfo<CustomerVehicleEntity> queryAll(SearchCustomerVO searchCondition, int offset, int max) {
        List<CustomerVehicleEntity> customerVehicles = dao.queryAll(searchCondition, new RowBounds(offset, max));
        return new PageInfo<CustomerVehicleEntity>(customerVehicles);
    }

    public PageInfo<CustomerActivityEntity> queryActivityCustomer(SearchCustomerVO searchCondition, int offset, int max) {
        List<CustomerActivityEntity> customerVehicles = dao.queryActivityCustomer(searchCondition, new RowBounds(offset, max));
        return new PageInfo<CustomerActivityEntity>(customerVehicles);
    }

    public PageInfo<CustomerVehicle> queryBindByPage(
            CouponSearch vo, int off, int max) {
        vo.setSkip(off);
        vo.setEnd(max);

        int total = dao.countBindByPage(vo.getCouponId());
        List<CustomerVehicle> clist = dao.selectBindByPage(vo);
        PageInfo<CustomerVehicle> info = new PageInfo<CustomerVehicle>(clist);
        info.setTotal(total);
        return info;
    }

}
